﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using WebMatrix.WebData;

namespace z.Controllers {
		[z.Filters.InitializeSimpleMembership]
	public class InstallController : Controller {
		//
		// GET: /Install/
		public ActionResult Index() {
			using (m.db.Database db = new m.db.Database()) {
				db.Database.CreateIfNotExists();
				if (db.UserProfiles.Count() == 0) {
					WebSecurity.CreateUserAndAccount("admin", "123");
					var role = new m.db.webpages_Roles();
					role.RoleName = "Admin";
					role.UserProfiles.Add(db.UserProfiles.Where(x => x.UserId == 1).Single());
					db.webpages_Roles.Add(role);
					db.SaveChanges();
					return View();
				} else {
					return RedirectToAction("Index", "Home");
				}
			}
		}
	}
}
